package com.example.batchprocessing.springbatch;

import com.example.batchprocessing.process.DealPeople;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class JdbcItemWriter implements ItemWriter<DealPeople>, InitializingBean{

    private JdbcTemplate jdbcTemplate;

    public JdbcItemWriter(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }


    @Override
    public void write(List<? extends DealPeople> DealPeoples) {

        //备份clear_atm

        try {
            for( DealPeople DealPeople : DealPeoples ){
                //删除当前表，然后更新
                jdbcTemplate.update( "");
	 }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // TODO Auto-generated method stub

    }
}
